home *** CD-ROM | disk | FTP | other *** search
- Path: news.eden.com!usenet
- From: Shane Sadler <nexus@eden.com>
- Newsgroups: comp.lang.c
- Subject: Re: [Q] functions returning structures
- Date: Sat, 02 Mar 1996 20:53:54 -0700
- Organization: Eden Matrix Services
- Message-ID: <313917D2.78CA51AB@eden.com>
- References: <4hasjj$opf@decaxp.harvard.edu>
- NNTP-Posting-Host: net-4-139.austin.eden.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
-
- Carlo Martino wrote:
- [snip]
- >
- > This work fine in SunOS. But when I ported this morning to HP-UX, the
- > value assigned to "new_color" was always screwy. I walked through it
- > in gdb, and the values within "get_color" were precisely what they ought
- > to be; it was only the returned structure that was mess up.
- >
- > So I changed things:
- >
- > RGB* get_color( VECTOR position );
- >
- > Which requires an extra free after I'm done with the values referenced by
- > the returned pointer. Not to mention the fact that screwing around with
- > the pointers, when all I real want is the values, is considerably less
- > elegant.
- >
- > What was going wrong? Is there a way to return structures without putting
- > them on the heap? When am I at risk for structures to become corrupt and
- > when am I OK?
-
- Carlos,
-
- I always thought pointers were *more* elegant than passing the whole
- structure to a function...oh well. :)
-
- The HP-UX compiler is notoriously anti-ANSI during a normal compile (and
- according to K&R1, C has no provisions for passing structures to
- functions), but you should have an ANSI compile mode. You'll have to
- look it up in your man pages because I don't remember what the flag is
- (-A?). Try compiling your code using the ANSI mode and see what happens.
-
- If that doesn't work, you can try declaring your structure as global and
- accessing it that way. It's inelegant, but no more so than what you're
- trying to do.
-
- Hope that helps you.
-
- -- Shane
- ===================================================================
- S. M. Sadler
- e-mail: nexus@eden.com
- Web: http://www.eden.com/~nexus
-